Test Failed
Pull Request — master (#2)
by Yo
01:40
created

wrapper.js ➔ ???   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 16.0213

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
nc 8
nop 1
dl 0
loc 11
rs 9.2
ccs 1
cts 11
cp 0.0909
crap 16.0213
1
"use strict";
2
3 1
const winston = require('winston');
4 1
const config = require('config');
5 1
const path = require('path');
6 1
const moment = require('moment');
7 1
const Logger = require('./Logger');
8
9 1
const loggerConfig = config.logger;
10
11 1
const formatFile = (options) => {
12
    return ' [' + options.level.toUpperCase() + ']'
13
        + '[' + moment(new Date()).format('YYYY-MM-DD HH:mm:ss') + ']'
14
        + (options.message ? ' ' + options.message : '')
15
        + (
16
            options.meta && Object.keys(options.meta).length
17
                ? ' ' + JSON.stringify(options.meta)
18
                : ''
19
        )
20
    ;
21
};
22
23 1
const formatConsole = (options) => {
24
    return winston.config.colorize(options.level) + ':'
25
        + (options.message ? ' ' + options.message : '')
26
        + (
27
            options.meta && Object.keys(options.meta).length
28
                ? ' ' + winston.config.colorize('data', JSON.stringify(options.meta))
29
                : ''
30
        )
31
    ;
32
};
33
34
/**
35
 * @type {winston.Logger} Default logger wrapper for the whole app. Use console output and a log file
36
 */
37 1
module.exports = new winston.Logger({
38
    transports: [
39
        new winston.transports.Console({
40
            level: config.debug === true ? 'debug' : loggerConfig.level,
41
            name: 'console',
42
            json: false,
43
            colorize: true,
44
            formatter: formatConsole
45
        }),
46
        new  winston.transports.File({
47
            name: 'default',
48
            level: config.debug === true ? 'debug' : loggerConfig.level,
49
            filename: path.resolve(loggerConfig.path, './server.log'),
50
            tailable: true,
51
            json: false,
52
            formatter: formatFile
53
        })
54
    ]
55
});
56